﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AppFx.BizTalk.Tests
{
    /// <summary>
    /// Tests the ensure class
    /// </summary>
    [TestClass]
    public class EnsureTests
    {
        /// <summary>
        /// Tests the invalid exception cant be constructed
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "The exception type you have specified does not derive from System.Exception")]
        public void TestInvalidExceptionType()
        {
            Ensure.IsTrue(false, "Test msg", typeof(FakeException));
        }
        /// <summary>
        /// Tests the invalid exception cant be constructed
        /// </summary>
        [TestMethod]
        [ExpectedException(typeof(ArgumentException), "The exception type does not have a valid constructor which accepts a single string input parameter")]
        public void TestInvalidExceptionConstructor()
        {
            Ensure.IsTrue(false, "Test msg", typeof(string));
        }
        /// <summary>
        /// Tests the istrue method
        /// </summary>
        [TestMethod]
        public void TestIsTrue()
        {
            const string ErrorMessage = "Test Error Msg";

            Ensure.IsTrue(true, "", typeof(ApplicationException));

            try
            {
                Ensure.IsTrue(false, ErrorMessage, typeof(ApplicationException));
                Assert.Fail("The code shouldnt execute this line");
            }
            catch (ApplicationException appEx)
            {
                Assert.IsTrue(appEx.Message == ErrorMessage);
            }
        }
        /// <summary>
        /// Tests the is false method
        /// </summary>
        [TestMethod]
        public void TestIsFalse()
        {
            const string ErrorMessage = "Test Error Msg";

            Ensure.IsFalse(false, "", typeof(ApplicationException));

            try
            {
                Ensure.IsFalse(true, ErrorMessage, typeof(ApplicationException));
                Assert.Fail("The code shouldnt execute this line");
            }
            catch (ApplicationException appEx)
            {
                Assert.IsTrue(appEx.Message == ErrorMessage);
            }
        }
        /// <summary>
        /// Tests the is not null method
        /// </summary>
        [TestMethod]
        public void TestIsNotNull()
        {
            const string ErrorMessage = "Test Error Msg";

            Ensure.IsNotNull(new object(), "", typeof(ApplicationException));

            try
            {
                Ensure.IsNotNull(null, ErrorMessage, typeof(ApplicationException));
                Assert.Fail("The code shouldnt execute this line");
            }
            catch (ApplicationException appEx)
            {
                Assert.IsTrue(appEx.Message == ErrorMessage);
            }
        }
        /// <summary>
        /// Tests the istrue method
        /// </summary>
        [TestMethod]
        public void TestIsNotNullOrEmpty()
        {
            const string ErrorMessage = "Test Error Msg";
            string temp = "s";

            Ensure.IsNotNullOrEmpty(temp, "", typeof(ApplicationException));

            try
            {
                Ensure.IsNotNullOrEmpty(null, ErrorMessage, typeof(ApplicationException));
                Assert.Fail("The code shouldnt execute this line");
            }
            catch (ApplicationException appEx)
            {
                Assert.IsTrue(appEx.Message == ErrorMessage);
            }
        }

        
    }
    /// <summary>
    /// Dummy exception class which isnt really an exception used for testing
    /// </summary>
    public class FakeException
    {
        /// <summary>
        /// Ctor
        /// </summary>
        public FakeException(string s)
        {

        }
    }
}


